package com.cyufeng.blog.service.mapper;

import com.cyufeng.blog.dto.ArticleDto;
import com.cyufeng.blog.dto.ReprintDto;
import com.cyufeng.blog.entity.Reprint;
import com.cyufeng.blog.entity.Reprint;

import java.util.ArrayList;
import java.util.List;

/**
 * 转载文章
 * @author Cyufeng
 * Data:2019.01.07
 */
public class ReprintMapper {
    public ReprintDto entityTodto(Reprint reprint){
        ReprintDto reprintDto = new ReprintDto();

        reprintDto.setId(reprint.getId());
        reprintDto.setLink(reprint.getLink());
        //boolean类型转成int   0否 1是
        if (reprint.getIsAuthorize() == 0)
            reprintDto.setIsAuthorize(false);
        else
            reprintDto.setIsAuthorize(true);

        reprintDto.setSort(reprint.getSort());
        reprintDto.setAuthor(reprint.getAuthor());
        reprintDto.setIsEnable(reprint.getIsEnable());
        reprintDto.setDr(reprint.getDr());
        reprintDto.setMadeTime(reprint.getMadeTime());
        reprintDto.setDelTime(reprint.getDelTime());

        return reprintDto;
    }
    public Reprint dtoToentity(ReprintDto reprintDto){
        Reprint reprint = new Reprint();

        reprint.setId(reprintDto.getId());
        reprint.setLink(reprintDto.getLink());
        //boolean类型转成int   0否 1是
        if (reprintDto.getIsAuthorize() == false)
            reprint.setIsAuthorize(0);
        else
            reprint.setIsAuthorize(1);

        reprint.setSort(reprintDto.getSort());
        reprint.setAuthor(reprintDto.getAuthor());
        reprint.setIsEnable(reprintDto.getIsEnable());
        reprint.setDr(reprintDto.getDr());
        reprint.setMadeTime(reprintDto.getMadeTime());
        reprint.setDelTime(reprintDto.getDelTime());

        return reprint;
    }
    //list集合
    public List<ReprintDto> entityTodto(List<Reprint> reprintList){
        List<ReprintDto> reprintDtoList = new ArrayList<>();
        for (int i = 0;i<reprintList.size();i++){
            Reprint reprint = reprintList.get(i);
            ReprintDto reprintDto = new ReprintDto();

            reprintDto.setId(reprint.getId());
            reprintDto.setLink(reprint.getLink());
            //boolean类型转成int   0否 1是
            if (reprint.getIsAuthorize() == 0)
                reprintDto.setIsAuthorize(false);
            else
                reprintDto.setIsAuthorize(true);

            reprintDto.setSort(reprint.getSort());
            reprintDto.setAuthor(reprint.getAuthor());
            reprintDto.setIsEnable(reprint.getIsEnable());
            reprintDto.setDr(reprint.getDr());
            reprintDto.setMadeTime(reprint.getMadeTime());
            reprintDto.setDelTime(reprint.getDelTime());

            reprintDtoList.add(reprintDto);
        }

        return reprintDtoList;
    }
    public List<Reprint> dtoToentity(List<ReprintDto> reprintDtoList){
        List<Reprint> reprintList = new ArrayList<>();
        for (int i = 0;i<reprintList.size();i++) {
            Reprint reprint = new Reprint();
            ReprintDto reprintDto = reprintDtoList.get(i);

            reprint.setId(reprintDto.getId());
            reprint.setLink(reprintDto.getLink());
            //boolean类型转成int   0否 1是
            if (reprintDto.getIsAuthorize() == false)
                reprint.setIsAuthorize(0);
            else
                reprint.setIsAuthorize(1);

            reprint.setSort(reprintDto.getSort());
            reprint.setAuthor(reprintDto.getAuthor());
            reprint.setIsEnable(reprintDto.getIsEnable());
            reprint.setDr(reprintDto.getDr());
            reprint.setMadeTime(reprintDto.getMadeTime());
            reprint.setDelTime(reprintDto.getDelTime());

            reprintList.add(reprint);
        }
        return reprintList;
    }
}
